Fix subtype check for identical late-resolvable conditional types (bug #10942)#4579
Fix subtype check for identical late-resolvable conditional types (bug #10942)#4579yt-catpaw wants to merge 3 commits intophpstan:2.1.xfrom
Conversation
|
|
||
| public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult | ||
| { | ||
| if ($this->equals($otherType)) { |
There was a problem hiding this comment.
It'd make sense to write some tests that test this method directly. Similar to this:
phpstan-src/tests/PHPStan/Type/UnionTypeTest.php
Lines 174 to 473 in 43e8099
Also, please review and maybe fix the isSuperTypeOf method as well.
There was a problem hiding this comment.
Implemented; please take a look
| $conditional, | ||
| ]); | ||
|
|
||
| $this->assertSame('Yes', $conditional->isSuperTypeOf($unionWithConditional)->describe()); |
There was a problem hiding this comment.
Please make a test with a data provider as it looks like in the test I linked. Then I'l try to come up with some data points that break your logic 😊
There was a problem hiding this comment.
Also write tests for both isSuperTypeOf and isSubtypeOf. Thanks!
There was a problem hiding this comment.
Added data-provider tests for isSuperTypeOf/isSubTypeOf (in tests/PHPStan/Type/LateResolvableTypeTraitTest.php).
closes phpstan/phpstan#10942
・Summary
Treat identical late-resolvable conditional types as compatible before resolving them.
Short-circuit when the same conditional appears inside a union.
Add regression test for bug #10942.
・Testing
vendor/bin/phpunit tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php --filter testBug10942